home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 274_01.zip / ARRAY.H < prev    next >
Text File  |  1993-04-01  |  8KB  |  313 lines

  1. /* Array Handling Package
  2. (C) Copyright 1985,1987,1988 James P. Cruse - All Rights Reserved
  3.  
  4. array.h
  5.  
  6. Version 1.00
  7.  
  8. This set of C header files is used to simplify array handling in C.
  9.  
  10. Included are routines to add, subtract, fill, negate, etc. 
  11.  
  12.  
  13. First, the Legal Issues:
  14.  
  15.  
  16. The routines are copyrighted by the author, and have been released as a
  17. user supported program. You may use this program on a trial basis, and if 
  18. you find it to be useful, or you continue using it, you must register it.
  19. Any Commercial enterprises using this software must register it immediately.
  20. You may not include the Source code of these routines with any 
  21. commercial package without written consent of the author. You may use 
  22. them to develop commercial programs upon registration.
  23. Simple registration of these routines is $10.00. If you wish to recieve 
  24. an upgrade of the routines, and trial usage of the STAT and function 
  25. equivalents, the registration fee is $25.00. To recieve a copy of the 
  26. Scientific Functions is $50.00. (See Description below).
  27.  
  28. Registration should be mailed to:
  29.  
  30.     James P. Cruse
  31.     919 Capitola Avenue
  32.     Suite 41
  33.     Capitola, CA 95010
  34.     (408) 475-7444 (m)
  35.  
  36.  
  37. I am currently developing other routines for C, as well as improving
  38. these. Routines that I am developing include: integer, float, and
  39. "user" defined functions (not macros) that are equivalent to these routines;
  40. Simple Statistical functions (mean,median,mode,r^2,s^2,standard deviation);
  41. Scientific Functions (polynomials, curve fits, convolutions); and
  42. Plotting routines for the IBM PC/XT/AT and compatibles (routines to plot on
  43. screen, printer or HP plotter x-y plots of up to 16 parameters in a 4
  44. windows).
  45.  
  46.  
  47.  
  48. Back to the routines:
  49.  
  50.  
  51. The routines are broken up into the following types:
  52.  
  53. Binary Operations    Add, Subtract, Multiply, etc. between 2 arrays
  54. Unary Operations    Negate, Assign, absolute, etc. an array
  55. Fill Operations        Fill array with index, index+off, values between x&y
  56. Info about Array    Min, Max, etc of an array
  57.  
  58. There are also routines to call a function on 1 or 2 arrays.
  59.  
  60. The routines work by substituting your call into a while loop. This was the 
  61. Only way I could find to use different types of arrays/constants in an 
  62. expression that would be compatible across a wide range of compilers/systems. 
  63. (I spent 3 months trying all kinds of different ways, but none would 
  64. work on ALL of the compilers I could test with, except this method).
  65.  
  66. The Functions all have a uniform naming format:
  67.  
  68.     X_NAME, where X is a, for single array operations, aa for 
  69.         2 array, ac for array & constant, and ca for contant & array
  70.         And NAME is the operation to be done. For Example:
  71.  
  72.         aa_add()    add two arrays
  73.         ac_add()    add array & constant
  74.         a_neg()        negate array
  75.         a_index()    fill array with index
  76.  
  77. They also have a uniform parameter format:
  78.  
  79. X_NAME(s,d,...)    where s is length of array, d is destination array, and
  80.     "..." varies for each type of operation:
  81.         Binary operations have 2 parameters, a and b or a and c
  82.         Unary operations have a single parameter a
  83.         info operations have a single parameter
  84.         and fill operations take multiple parameters.
  85.  
  86.     The function can also take other parameters, depending on the 
  87.     operation. 
  88.  
  89.  
  90. The Functions Are:
  91.  
  92.  
  93. Binary Operations: (a_binop.h)
  94.     add, sub, mul, div, min, max, mod (%,modulo),
  95.     equ (==), geq (>=), leq (<=), gtr (>), les (<),
  96.     fun (function), t_fun (typed function)
  97.  
  98.     aa_add(n,d,a,b)        d[] = a[] + b[]
  99.     ac_min(n,d,a,c)        d[] = ARR_MIN(a[],c)
  100.     ca_sub(n,d,c,a)        d[] = c - a[]
  101.  
  102.     aa_fun(n,d,a,b,f)    d[] = f(a[],b[])
  103.     ac_t_fun(n,d,a,c,f,t)    d[] = f( (t) a[] , (t) c )
  104.  
  105.  
  106. Unary Operations: (a_unop.h)
  107.     cpy (copy,assign), neg (negate), abs (absolute value), 
  108.     rsum (running sum), rprod (running product),
  109.     rmin (running min), rmax (running max),
  110.     fun (function), t_function (typed function)
  111.     scale (scale&offset)
  112.  
  113.     a_cpy(n,d,a)        d[] = a[] 
  114.     a_rsum            d[i] = d[i-1] + a[i]
  115.     a_rmax            d[i] = ARR_MAX( d[i-1] , a[i] )
  116.  
  117.     a_scale(n,d,a,s,o)    d[] = o + s*a[]
  118.  
  119.     a_fun(n,d,a,f)        d[] = f(a[]])
  120.     a_t_fun(n,d,a,f,t)    d[] = (t) f( (t) a[] )
  121.  
  122.  
  123. Fill Operations: (a_fill.h)
  124.     index, indoff (index+offset), fill (exclusive), 
  125.     ifill (inclusive), t_fill (typed fill), t_ifill (typed inc. fill)
  126.     scale (scale&offset), 
  127.     assign, f_fun (function), i_fun, (function w/index param),
  128.     t_i_fun (typed function w/index param)
  129.  
  130.     a_indoff(n,d,c)        d[i] = i + c
  131.     a_assign(n,d,c)        d[] = c
  132.     a_i_scale(n,d,s,o)    d[i] = s*i + o
  133.  
  134.     a_fill(n,d,s,e)        d[0] = s, d[i] = s+(e-s)/n, d[n] (would be) e 
  135.     a_t_ifill(n,d,s,e)    d[0] = s, d[i] = s+((t)(e-s))/(n-1), d[n-1] = e
  136.  
  137.     a_f_fun(n,d,f)        d[] = f()
  138.     a_t_i_fun(n,d,f,t)    d[i] = f( (t) i )
  139.  
  140.  
  141. Info Operations: (a_info.h)
  142.     sum, prod, min, max, minmax
  143.  
  144.     a_sum(n,d,a)        d = a[0] + a[1] + ... + a[n-1]
  145.     a_min(n,d,a)        d = min( a[0] , a[1] , ... , a[n-1] )
  146.     a_minmax(n,l,u,a)    l = min( a[0] , a[1] , ... , a[n-1] ),
  147.             and    u = max( a[0] , a[1] , ... , a[n-1] )
  148.  
  149.  
  150. OPTIONS:
  151.  
  152. Compiler Dependent Options:
  153.     Set ARR_IF_NEEDED to 1 if you cannot have a curly brace without
  154. a proceeeding if or while (see ARR_IF_NEEDED example below).
  155.     There are macros for taking the MIN and MAX of two parameters, and
  156. for getting the ABS of a parameter. You can modify them if you need to.
  157. Note: they are only used in the min and max calculations, but NOT the 
  158. the combined minmax functions. I use an if-else-then there.
  159.  
  160. Customization:
  161.     You can turn on or off the various #defines, so that only 
  162. certain of the routines are included by default. You can override these 
  163. defaults by defining the #define to 1 prior to including array.h, or you
  164. may include the file directly.
  165.  
  166.     You may modify the variable name the program uses for declaring
  167. it's index to anything you want, I found the default to be acceptable.
  168.     
  169.     You may also modify the "type" of the index variable, this allows
  170. you to declare it as a register variable, or convert it to a non-int.
  171.  
  172.  
  173. COMMENTS:
  174.  
  175.     See each file for further discussion of each type of functions.
  176.  
  177.     The routines as written should be usable on a wide variety of
  178. machines (I believe they are both K&R and ANSII compatible).
  179.  
  180.     If you have any problems, comments, or routines you would
  181. like to have (now or in the future), I would be glad to hear from you.
  182.  
  183.  
  184.             Sincerely,
  185.  
  186.             James P. Cruse
  187.  
  188. */    
  189.  
  190. /* have we been loaded? */
  191. #ifndef    ARR_IF_NEEDED
  192.  
  193.  
  194.  
  195.  
  196. /* Global Declarations */
  197.  
  198. /* set to true if you cannot have {} in any location in a function */
  199. /* e.g.:
  200.     main()
  201.     {
  202.     int i;
  203.     {            does this curly brace generate an error?
  204.     i = 7;
  205.     }
  206.     printf("%d",i);
  207.     }
  208. */
  209. #define    ARR_IF_NEEDED    0    /* needs an if */
  210.  
  211.  
  212. /* what type and name do you want for the indexing variable? */
  213. #define    ARR_IND        ijklmnop
  214. #define    ARR_TYPE_IND    int
  215.  
  216.  
  217. /* How do you want to determine the MIN/MAX of two elements */
  218. #define    ARR_MIN(X,Y)    ( (X) < (Y) ? (X) : (Y) )    
  219. #define    ARR_MAX(X,Y)    ( (X) > (Y) ? (X) : (Y) )
  220.  
  221.  
  222. /* how do you want to determine the ABSolute value of an element */
  223. #define    ARR_ABS(X)    ( (X) < 0 ? -(X) : (X) )
  224.  
  225.  
  226. /* which functions do you want loaded by default? */
  227.  
  228.  
  229. /* Unary Operations */
  230.  
  231. #ifndef    ARR_UNOP    /* overriden? */
  232.  
  233. #define    ARR_UNOP    1    /* unary (d[] = a[]) */
  234.  
  235. #endif
  236.  
  237.  
  238.  
  239. /* Binary Operations */
  240.  
  241. #ifndef    ARR_BINOP    /* overridden */
  242.  
  243. #define    ARR_BINOP    1    /* Binary (d[] = a[] + b[]) */
  244.  
  245. #endif
  246.  
  247.  
  248.  
  249. /* Fill Operations */
  250.  
  251. #ifndef    ARR_FILL     /* overridden */
  252.  
  253. #define    ARR_FILL    1    /* fill array (d[] = i*x+b) */
  254.  
  255. #endif
  256.  
  257.  
  258.  
  259.  
  260. /* Information Operations */
  261.  
  262. #ifndef    ARR_INFO     /* overridden */
  263.  
  264. #define    ARR_INFO    1    /* info about array (min,max) */
  265.  
  266. #endif
  267.  
  268.  
  269.  
  270.  
  271. /* Internal defines */
  272. #if    ARR_IF_NEEDED        /* do we need an if statement? */
  273. #define    ARR_IF1    if(1)             /* declare if */
  274. #define    ARR_IF2    else ;            /* close if */
  275. #else                /* nope -> do nothing */
  276. #define    ARR_IF1    
  277. #define    ARR_IF2 
  278. #endif
  279.  
  280.  
  281. /* now we shall include wanted files */
  282.  
  283. #if    ARR_UNOP
  284.  
  285. #include "a_unop.h"
  286.  
  287. #endif
  288.  
  289. #if    ARR_BINOP    
  290.  
  291. #include "a_binop.h"
  292.  
  293. #endif
  294.  
  295. #if    ARR_FILL     
  296.  
  297. #include "a_fill.h"
  298.  
  299. #endif
  300.  
  301. #if    ARR_INFO     
  302.  
  303. #include "a_info.h"
  304.  
  305. #endif
  306.  
  307.  
  308.  
  309.  
  310.  
  311. /* done */
  312. #endif    /* ARR_IF_NEEDED , -> loaded already */
  313.